package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo
{
    public static void main(String[] args)
    {
        ExecutorService pool = Executors.newFixedThreadPool(3);
        for (int i = 0 ; i < 5 ; i++)
        {
            Runnable runnable = new Runnable()
            {
                @Override
                public void run()
                {
                    Thread thread = Thread.currentThread();
                    System.out.println(thread + " is running ");
                    try
                    {
                        Thread.sleep(1000);
                    } catch (InterruptedException e)
                    {
                        throw new RuntimeException(e);
                    }
                    System.out.println(thread + "is overed");
                }
            };
            System.out.println("give a task to pool");
            pool.execute(runnable);
        }
        pool.shutdown();
    }
}
